﻿using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using INSE6260.OnlineBanking.Model.Transaction;

namespace INSE6260.OnlineBanking.Repository.EF.Mappings
{
    class TransactionConfiguration: EntityTypeConfiguration<Transaction>
    {
        public TransactionConfiguration()
        {					
    		this.HasKey(t => t.Id);		
    		this.ToTable("Transaction");
    		this.Property(t => t.Id).HasColumnName("Id");
    		this.Property(t => t.TransactionDate).HasColumnName("TransactionDate");
            this.Property(t => t.Amount).HasColumnName("Amount");    		
            this.Property(t => t.FromAccountId).HasColumnName("FromAccountId");
    		this.Property(t => t.ToAccountId).HasColumnName("ToAccountId");
            this.Property(t => t.Balance).HasColumnName("Balance");
    		this.HasRequired(t => t.SourceAccount).WithMany(t => t.Transactions).HasForeignKey(d => d.FromAccountId);
    		this.HasRequired(t => t.DestinationAccount).WithMany(t => t.Transactions1).HasForeignKey(d => d.ToAccountId);


            this.Map<Withdraw>(m => m.Requires("TransactionType").HasValue("Withdraw"));
            this.Map<Deposit>(m => m.Requires("TransactionType").HasValue("Deposit"));
            this.Map<MakePayment>(m => m.Requires("TransactionType").HasValue("Payment"));
            this.Map<Trasnfer>(m => m.Requires("TransactionType").HasValue("Trasnfer"));

    	}
    }
}